package argo.hot150;


import java.util.Arrays;

public class Merge2Arr {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if (n == 0) {
            return;
        }
        int[] res = new int[m + n];
        int l1 = 0, l2 = 0, l = 0;
        while (l1 < m && l2 < n) {
            if (nums1[l1] < nums2[l2]) {
                res[l] = nums1[l1];
                l1++;
            } else {
                res[l] = nums2[l2];
                l2++;
            }
            l++;
        }

        while (l1 < m) {
            res[l] = nums1[l1];
            l1++;
            l++;
        }
        while (l2 < n) {
            res[l] = nums2[l2];
            l2++;
            l++;
        }

        for (int i = 0; i < m + n; i++) {
            nums1[i] = res[i];
        }
    }


    public static void main(String[] args) {
        int[] ints1 = {1, 2, 3, 0, 0, 0};
        int[] ints2 = {2, 5, 6};
        new Merge2Arr().merge(ints1, 3, ints2, 3);
        System.out.println(Arrays.toString(ints1));
    }

}
